package com.fau.wmbj.server.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单
 *
 * @author jiawei
 * @version 1.0
 * @datetime 2024-03-06 16:10
 */
@Getter
@Setter
@Entity(name = "f_order_")
@TypeDef(name = "json", typeClass = JsonStringType.class)
public class Order extends BaseEntity<Long> implements Serializable {

    /**
     * 所属公司
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "company_id")
    private Company company;

    /**
     * 订单号
     */
    @Column(name = "order_no")
    private String orderNo;

    /**
     * 表格数据
     */
    @Lob
    @Column(name = "table_data")
    @Type(type = "json")
    private Map<String, Object> tableData = new HashMap<>();

    /**
     * 订单成员
     */
    @JsonIgnore
    @OneToMany(mappedBy = "order_", fetch = FetchType.EAGER)
    private List<OrderMember> orderMembers = new ArrayList<>();

    /**
     * 引用模板
     */
    @Column(name = "template_id")
    private Long templateId;

    /**
     * 流程ID
     */
    @Column(name = "process_id")
    private String processId;

    @Transient
    private Template template;

    @Transient
    private List<Map<String, Object>> body = new ArrayList<>();

}
